package com.zl.learning.io;

import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

public class TestRuntime {
    public static void main(String[] args) throws IOException {
        Runtime runtime = Runtime.getRuntime();
        Process process = runtime.exec("where git");
        List<String> lines = IOUtils.readLines(process.getInputStream(), StandardCharsets.UTF_8);
        if (lines.size() > 0) {
            String cmd = lines.get(0);
            cmd = cmd.replace("cmd\\git.exe", "bin\\bash.exe");
            cmd = " \"" + cmd + "\" ";
            cmd += " --login -i";
//            cmd = "cmd /k start " + cmd;
            System.out.println(cmd);
            process = runtime.exec(cmd,new String[]{cmd});
//            lines = IOUtils.readLines(process.getInputStream(), StandardCharsets.UTF_8);
//            System.out.println(lines);
        }
        process = runtime.exec("%bash%\\bash.exe",new String[]{"bash=\"C:\\Program Files\\Git\\bin\""});
//       ProcessBuilder builder = new ProcessBuilder();
//        builder.environment().put("bash","C:\\Program Files\\Git\\bin");
//        System.out.println(builder.environment());
//        builder.environment().put("python","C:\\Python27\\python.exe");

//        builder.command("cmd /k start python");
//        runtime.exec("cmd /c set bash=C:\\Program Files\\Git\\bin\\bash.exe && start cmd ");
//        builder.start();
    }
}
